<?php

/*
 *  Action $5
 * 
 *  +1 Cards, +1 Actions
 * 
 *  Look at the top 4 cards of your deck. Discard any number of them.
 *  Put the rest back on top in any order.
 * 
 */

class Cartographer extends Card implements iAction, iKingdom, iHinterlands {

    public function __construct() {
        parent::__construct("Cartographer", 5);
    }
    
     public function getDescription() {
        return array(
            "+1 Cards",
            "+1 Action",
            "Look at the top 4 cards of your deck. Discard any number of them.",
            "Put the rest back on top in any order.");
    }

    public function play(Game $game) {

        $game->addActions(1);
        $drawed_cards = $game->drawCards(1);
        ScreenDisplay::addScreenMessage($game, true, "get +1 action and draw " . nicePrint($drawed_cards), "gets +1 action and draws " . sizeof($drawed_cards) . " cards");

        // get the cards
        $cards = $game->removeCardsFromDrawDeck(4);

        // discard any of them
        if (sizeof($cards) > 0) {
            $discardedCards = MySocket::GetUserReply($game, Input_ChooseMany, $cards, 0, -1, null, "Choose cards to discard");
            ScreenDisplay::addScreenMessage($game, true, "discard  " . nicePrint($discardedCards), "discards " .sizeof($discardedCards). " cards");
            $game->discardTempDiscardCards($discardedCards);
        }


        // put the rest back in any order
        if ((sizeof($cards) > 0) && (sizeof($discardedCards) > 0)) {
            foreach ($discardedCards as $dc) {
                $i = 0;
                foreach ($cards as $c) {
                    if ($c->getKey() == $dc) {
                        array_splice($cards, $i, 1);
                        break;
                    }
                    $i += 1;
                }
            }
        }
        if (sizeof($cards) > 0) {
            $output = MySocket::GetUserReply($game, Input_Reorder, $cards, -1, -1, null, "Put cards back in any order");
            ScreenDisplay::addScreenMessage($game, true, "put " . nicePrint($output) . " on top of your deck", "puts " . sizeof($output) . " cards on top of his deck");
            $output = array_reverse($output);
            foreach ($output as $pbc) {
                $game->putCardOnTopOfDrawDeck($pbc);
            }
        } else {
            ScreenDisplay::addScreenMessage($game, true, "put nothing back on your deck", "puts nothing back on his deck");
        }

        $game->cardActionFinished();
        return true;
    }

}

?>